<?php
/* @var $this UserController */
/* @var $model User */

$this->breadcrumbs=array(
	'Anggota'=>array('semua'),
	'Menej Anggota',
);

$this->pageTitle=Yii::app()->name . " - Menej Anggota";

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#user-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<div class="kolom-1">
	<h1 class="judul-halaman">MENEJ ANGGOTA</h1>
	<div class="latar-putih">
		<div id="statusMsg">
			<?php if(Yii::app()->user->hasFlash('success')):?>
				<div class="alert alert-success">
					<?php echo Yii::app()->user->getFlash('success'); ?>
				</div>
			<?php endif; ?>
			 
			<?php if(Yii::app()->user->hasFlash('error')):?>
				<div class="alert alert-error">
					<?php echo Yii::app()->user->getFlash('error'); ?>
				</div>
			<?php endif; ?>
		</div>
	<?php echo CHtml::link('Pencarian Lanjutan','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php 
	//untuk ganti text saat menghapus user

	$this->widget('bootstrap.widgets.TbExtendedGridView', array(
		'id'=>'user-grid',
		'filter' => $model,
		'type' => 'striped bordered',
		'sortableRows'=>true,
		'afterSortableUpdate' => 'js:function(id, position){ console.log("id: "+id+", position:"+position);}',
		'dataProvider' => $model->search(),
		'template' => "{items}",
		'columns'=>array(
			array(
				'header'=>'#',
				'value'=>'$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1',
				'htmlOptions' => array('width' => '10px'),
				'headerHtmlOptions' => array('style'=>'text-align:center; vertical-align:middle;'),
			),
			array(
				'name'=>'username',
				'htmlOptions' => array('width' => '50px'),
				'headerHtmlOptions' => array('style'=>'text-align:center; vertical-align:middle;'),
			),
			array(
				'name'=>'nama',
				'htmlOptions' => array('width' => '150px'),
				'headerHtmlOptions' => array('style'=>'text-align:center; vertical-align:middle;'),
			),
			array(  
				'name'    => 'angkatan_id',
				'value'=>'(Angkatan::model()->findByPk($data->angkatan_id)->angkatan)',
				'filter' => CHtml::listData(Angkatan::model()->findAll(array('order'=>'id')), 'id', 'angkatan'),
				'htmlOptions' => array('width' => '100px'),
				'headerHtmlOptions' => array('style'=>'text-align:center; vertical-align:middle;'),		
			), 
			array(
				'class'=>'bootstrap.widgets.TbButtonColumn',
				'afterDelete'=>'function(link,success,data){ if(success) $("#statusMsg").html(data); }',
				'buttons' => array('delete' =>
					array(
						'url' => 'Yii::app()->controller->createUrl("delete",array("id"=>$data->primaryKey))',
						'label' => 'hapus',
						'options' => array( 'class' => 'grid_action_set1'),
					),
					'update' => array(
						'options' => array('class' => 'grid_action_set'),
						'label' => 'Edit',
						'url' => 'CController::createUrl("/user/updateProfil", array("id"=>$data->primaryKey))',
					),
					'view' => array(
						'options' => array('class' => 'grid_action_set'),
						'label' => 'Lihat',
					),
				)
			),
        ),
	));
?>
		<div align="right" class="kolom-1" style="margin-top:10px">
			<a href="<?php echo Yii::app()->createUrl('/user/create'); ?>" class="tombol">TAMBAH ANGGOTA</a>
		</div>
	</div>
	
</div>
